var MeldAssistant = Class.create(AbstractModule, {


setupWidgets: function() {

		//About
		this.controller.setupWidget(Mojo.Menu.appMenu, {
			omitDefaultItems: true
		}, {
			visible: true,
			items: [
      		Mojo.Menu.editItem,
			{ label: "Disclaimer", command: "do-disclaimer" },					
				{ label: "License", command: "do-license" },
				{ label: "Help", command: "do-help" }
			]
		});

this.help = true;

  this.toggleModel = {
			dialysisCHK: false
		};

	this.toggleunit =
	{
		modelProperty: 'togglestate',
		trueLabel: 'SI',
	falseLabel: 'US'
	};
	this.togglemodel = {
		togglestate: true
	};
	
	
		this.controller.setupWidget("scoring", {
			label: "Scoring<sup>*</sup>",
			choices: [
				{ label: "UNOS", value: 1},
				{ label: "Original", value: 0}
			]
		}, this.scoringModel = {
			value: 1
		});
	
	this.controller.setupWidget("unitField", this.toggleunit, this.togglemodel);
	this.controller.listen("unitField", Mojo.Event.propertyChanged, this.unitChanged.bindAsEventListener(this));

	
	this.controller.setupWidget("bilirubinField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {});
	
		this.controller.setupWidget("inrField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {});
	
	this.controller.setupWidget("creatinineField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: creatinine});
	
	this.controller.setupWidget("dialysisCHK", {
			modelProperty: "dialysisCHK"
		}, this.toggleModel);
	
},

unitChanged: function() {
//change unit display in bmi scene
var unitchoice = this.togglemodel.togglestate;

if (!unitchoice){
$("bilirubinUnit").update("<span class=\"si\">(mg/dL)</span>");
$("creatinineUnit").update("<span class=\"si\">(mg/dL)</span>");
}

if (unitchoice){
$("bilirubinUnit").update("<span class=\"si\">(&mu;mol/l)</span>");
$("creatinineUnit").update("<span class=\"si\">(&mu;mol/l)</span>");
}
},


	calculate: function() {
	var result = meldcalc(this.togglemodel.togglestate, this.scoringModel.value, $("bilirubinField").mojo.getValue(),$("inrField").mojo.getValue(), $("creatinineField").mojo.getValue(), this.toggleModel.dialysisCHK);
  creatinine=result.creatinine;
	return "The MELD is " + result.score;
	}
});





